import 'package:flutter/material.dart';
import 'package:flutter_billi/model/video_detail.dart';
import 'package:flutter_billi/model/video_model.dart';
import 'package:flutter_billi/util/color.dart';
import 'package:flutter_billi/util/format_util.dart';
import 'package:flutter_billi/util/view_util.dart';

///视频点赞 分享 工具栏

class VideoToolBar extends StatelessWidget {
  final VideoDetailMo detailMo;
  final VideoModel videoModel;
  final VoidCallback onLike;
  final VoidCallback onUnLike;
  final VoidCallback onCoin;
  final VoidCallback onShare;
  final VoidCallback onFavorite;
  const VideoToolBar({
    Key key,
    @required this.detailMo,
    @required this.videoModel,
    this.onLike,
    this.onUnLike,
    this.onCoin,
    this.onShare,
    this.onFavorite,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 15, bottom: 10),
      margin: EdgeInsets.only(bottom: 15),
      decoration: BoxDecoration(border: borderLine(context)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          _buildIconText(Icons.thumb_up_alt_rounded, videoModel.like, onClick: onLike, tint: detailMo?.isLike),
          _buildIconText(
            Icons.thumb_down_alt_rounded,
            "不喜欢",
            onClick: onUnLike,
          ),
          _buildIconText(
            Icons.monetization_on,
            videoModel.coin,
            onClick: onCoin,
          ),
          _buildIconText(Icons.grade_rounded, videoModel.favorite,
              onClick: onFavorite, tint: detailMo?.isFavorite ?? false),
          _buildIconText(Icons.share_rounded, videoModel.share, onClick: onShare)
        ],
      ),
    );
  }

  _buildIconText(IconData iconData, text, {bool tint = false, onClick}) {
    print(tint);
    if (text is int) {
      text = countFormat(text);
    } else if (text == null) {
      text = "";
    }
    tint = tint == null ? false : tint;
    return InkWell(
      onTap: onClick,
      child: Column(
        children: [
          Icon(
            iconData,
            color: tint ? primay : Colors.grey,
            size: 20,
          ),
          hiSpace(height: 5),
          Text(
            text,
            style: TextStyle(color: Colors.grey, fontSize: 12),
          )
        ],
      ),
    );
  }
}
